package com.sky.controller.admin;

import com.sky.aop.AutoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.pojo.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description DishController
 * @Author zhengyuan&junjun
 * @Date 2024-10-02
 */
@RestController
@RequestMapping("/admin/dish")
@Slf4j
@Api(tags = "菜品管理")
public class DishController {
@Autowired
private DishService dishService;


@GetMapping("/page")
@ApiOperation("分页查询菜品")

public  Result<PageResult> page(DishPageQueryDTO dto){

    PageResult pageResult = dishService. page(dto);


    return Result.success(pageResult);
}

@PostMapping
@ApiOperation("新增菜品")
 public  Result<String> update(@RequestBody DishDTO dto){

    dishService.update(dto);


    return Result.success();

 }

  /**
   * 修改菜品信息时进行数据回显
   ***/
   @GetMapping("/{dishId}")
    @ApiOperation("根据id查询菜品")

    public  Result<DishVO> getById(@PathVariable("dishId")Long dishId){

    DishVO dishVO = dishService. getById(dishId);


    return  Result.success(dishVO);


    }

    @PutMapping
    @ApiOperation("修改菜品")

    public  Result<DishVO>  insert(@RequestBody DishDTO dto){

         dishService.insert(dto);

        return  Result.success();

    }

    @DeleteMapping
    public  Result<String> deleterdish(@RequestParam List<Long>ids){

       return   dishService.deleterdish(ids);


    }
    @PostMapping("/status/{status}")
    public  Result<String> DishActivation(Long id,@PathVariable("status") Integer status){

       dishService.DishActivation(id,status);


       return  Result.success();

    }

    @GetMapping("/list")
    @ApiOperation("根据分类id查询菜品")
    public  Result<List<Dish>> list(Long categoryId){

       List<Dish> dishes =  dishService.list(categoryId);

        return  Result.success(dishes);
    }




}
